The View is implemented using Java Server Pages (JSP). Java Server Pages are normally filled with embedded Java code, but the Struts framework provides extension tags for numerous functions including generating and populating html controls (<html:text>), managing errors (<html:errors>), and iterating over data lists (<logic:iterate>). The following JSP files are used in Dwarf Manager:
Note the following are static screen shots. This site is not dynamically hosted.
|Generated HTML||JSP Source (View->Source)|
The Model is implemented as Java Beans subclassed from ActionForm. Three Form beans were defined:
The Controller portion of the struts framework automatically copies data between the Model Form Beans and the View JSP pages. The controller logic for each page is implemented in subclasses of the Action class:
The page flow and the relationships between the models, views, and controllers are configured in the struts-config.xml file.
Underneath the model the data is stored in the Postgresql SQL database. The following database files were used:
Java Bean data objects were defined to encapsulate data returned from the database:
Rows from the Database object are initially returned as a DbRowSet, but are copied to lists of data objects because the Struts APIs and tag libraries operate on Java Beans, not list-of-hash-style RowSets [note the difference with ASP.NET, whose controls accept ADO.NET database DataSets directly]. Database queries are performed inside Mgr objects:
Struts also supports separate message catalogs for localization. Dwarf Manager does not use this facility, except the Form validation will return error messages from the ApplicationResources.properties file.
While Java Dwarf Manager does require more code than the C# equivalent, some of this code can be produced using a Code Generator.
The simple back-end jdbc database classes can also be replaced with EJBs.
The source for the Java Dwarf Manager web site is available in this tar file. All code was developed using Java 1.3.1 on Mac OS X.